PROJECT(kfext_xtp)

if(WIN32)
    SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
endif()

IF(NOT XTP_API_VERSION)
    SET(XTP_API_VERSION 1.1.19.2)
ENDIF()

IF(WIN32)
    SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
    SET(API_LIB_PATH api/${XTP_API_VERSION}/lib/win64/dll)
ENDIF()
IF(UNIX AND NOT APPLE)
    SET(API_LIB_PATH api/${XTP_API_VERSION}/lib/linux_centos7)
ENDIF()
IF(APPLE)
    SET(XTP_API_VERSION 1.1.18.13)
    SET(API_LIB_PATH api/${XTP_API_VERSION}/lib/macosx)
ENDIF()

INCLUDE_DIRECTORIES(api/${XTP_API_VERSION}/include)
LINK_DIRECTORIES(${API_LIB_PATH})

AUX_SOURCE_DIRECTORY(src SOURCE_FILES)

SET(KF_EXTENSION_BUILD_DIR ${KF_EXTENSIONS_BUILD_DIR}/xtp)

CONFIGURE_FILE(__init__.py "${KF_EXTENSION_BUILD_DIR}/__init__.py")
CONFIGURE_FILE(package.json "${KF_EXTENSION_BUILD_DIR}/package.json")

PYBIND11_ADD_MODULE(${PROJECT_NAME} SHARED ${SOURCE_FILES})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${KF_EXTENSION_BUILD_DIR})
IF(WIN32)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${KF_EXTENSION_BUILD_DIR})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${KF_EXTENSION_BUILD_DIR})
ENDIF()

TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE xtptraderapi xtpquoteapi wingchun yijinjing)
FILE(GLOB DLLS "${API_LIB_PATH}/*")
FILE(COPY ${DLLS} DESTINATION ${KF_EXTENSION_BUILD_DIR})

ADD_CUSTOM_COMMAND(OUTPUT package_json
        COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/package.json ${KF_EXTENSION_BUILD_DIR})
ADD_CUSTOM_TARGET(kfext_xtp_package_json ALL DEPENDS package_json)
